<template>
  <div class="systemTablesList">
    <CommonBtn label-name="表权限设定管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+item.value}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event == 'detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_ADDTABLEPERMISSION" :edit-url="$api.API_UPDATETABLEPERMISSIONS"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_TABLEPERMISSIONEXPORT" :conditions="conditions"></CommonExport>
    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :disable-url="$api.API_TPPERSONNELINFO_BAN"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'systemTablesList',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.DETAIL,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'tablesName',
                        label:'数据库表名',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'tablesMemo',
                        label:'表描述',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl:this.$api.API_GETTABLEPERMISSIONSLIST,
                button:null,
                add:{
                    label:'表权限设定',
                    addItems:[
                        {name:'数据库表名',prop:'tablesName',required:true,type:'text'},
                        {name:'表描述',prop:'tablesMemo',type:'text',required:true},
                        {name:'备注',prop:'memo',type:'textarea'}
                    ],
                },
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()'  || item.event == 'disable()' || item.event == 'detail()'){
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                this.$delete (this.row,'createTime')
                this.$delete (this.row,'modifyTime')
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport, CommonList,CommonBtn,CommonEdit,SearchPopUp,EnsurePopUp}
    }
</script>
